package com.shuiyun.chat.controller;


import com.shuiyun.chat.entity.Result;
import com.shuiyun.chat.entity.bo.SendMsgBO;
import com.shuiyun.chat.entity.bo.UserBO;
import com.shuiyun.chat.entity.bo.UserUpdateBO;
import com.shuiyun.chat.entity.message.LoginResponseMessage;
import com.shuiyun.chat.entity.vo.UserVO;
import com.shuiyun.chat.service.UserService;
import io.netty.channel.Channel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shuiyun
 * @since 2021-05-12
 */
@Slf4j
@Api(tags="用户接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/{id}")
    @ApiOperation("通过ID获取对象")
    public Result<UserVO> get(@PathVariable @ApiParam(required = true, value = "对象ID") Long id) {
        return Result.ok(userService.get(id));
    }

    @PostMapping
    @ApiOperation("新增对象")
    public Result<Object> add(@RequestBody UserBO userBO){
        Object id = userService.add(userBO);
        return Result.ok(id);
    }

    @PutMapping
    @ApiOperation("修改对象")
    public Result update(@RequestBody UserUpdateBO userUpdateBO){
        userService.update(userUpdateBO);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除对象")
    public Result delete(@PathVariable Long id) {
        userService.delete(id);
        return Result.ok();
    }

    @PostMapping("login")
    @ApiOperation("登录")
    public Result<LoginResponseMessage> login(UserBO userBO){
        LoginResponseMessage message = userService.login(userBO);
        return Result.ok(message);
    }


}

